#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <string.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
#include <linux/socket.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>

#define WIRED_GENL_FAMILY_NAME "DEMO"

struct nl_sock *wired_sock;
int wired_genl_family;

int main(int argc, char **argv)
{
    int ret = -1;
    struct nl_msg *msg;
    struct nlattr *attr;

	printf("hello netlink \n");

    wired_sock = nl_socket_alloc();
    if (wired_sock == NULL) {
        printf("Unable to allocate socket");
        return -1;
    }

    ret = genl_connect(wired_sock);
    if (ret < 0) {
        printf("genl sock connect failed");
        return -1;
    }

    wired_genl_family = genl_ctrl_resolve(wired_sock, WIRED_GENL_FAMILY_NAME);
    if (wired_genl_family < 0) {
        printf("Unable to resolve wired family");
        return -1;
    }
    printf("hello generic netlink family:[%d] \n", wired_genl_family);

    return 0;

    // nl_socket_disable_seq_check(wired_sock);
    // nl_socket_modify_cb(wired_sock, NL_CB_VALID, NL_CB_CUSTOM, wired_parse_cb, inter);
    // printf("wam_ov_wired_genl_init success");

    // msg = nlmsg_alloc();
    // if (msg == NULL) {
    //     printf("Unable to allocate message");
	// 	goto err;
    // }

    // genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, wired_genl_family, 0, 0, WIRED_C_INIT_WAM, 0);

    // attr = nla_nest_start(msg, WIRED_A_PORTS);
    // wired_genl_put_wired(msg, inter);
    // nla_nest_end(msg, attr);

    // ret = nl_send_auto_complete(wired_sock, msg);
    // nlmsg_free(msg);
    // if (ret < 0) {
    //     printf("wired nl_send_auto_complete failed");
	// 	goto err;
    // }

    // printf("wired nl_send_auto_complete success,ret = %d", ret);

    // eloop_register_read_sock(wired_sock->s_fd, wired_genl_rcv_msg, NULL, NULL);
    // return 0;
}